package com.szjlxh.data.utils;

import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;

import java.lang.reflect.Type;

/**
 * Created by liutao on 16/3/18.
 */
public class GsonObjectFormatter<T> {
    private final Gson gson;
    private final String jsonString;

    public GsonObjectFormatter(String jsonString) {
        gson = new Gson();
        this.jsonString = jsonString;
    }

    public T getObjectFromType(Type userEntityType) throws Exception {
        if (jsonString==null) throw new NullPointerException("json string parsed error!");
        T userEntity = this.gson.fromJson(jsonString, userEntityType);
        return userEntity;
    }
}
